import store from './vuex/store'
import Login from './views/Login.vue'
import Home from './views/Home.vue'
import User from './views/sysmanager/User.vue'
import Role from './views/sysmanager/Role.vue'
import Action from './views/sysmanager/Action.vue'
import Menu from './views/sysmanager/Menu.vue'
import Manufacture from './views/manufacture/Manufacture.vue'
import ManufactureDetail from './views/manufacture/ManufactureDetail.vue'
import ManufactureCompany from './views/manufacture/ManufactureCompany.vue'
import JoinApply from './views/manufacture/JoinApply.vue'
import ModifyPassword from './views/personal/ModifyPassword.vue'
import PersonalInfo from './views/personal/PersonalInfo.vue'
import CompanyDetail from './views/company/CompanyDetail.vue'

let routes = [
    {
        path: '/',
        component: Login,
        name: '',
        hidden: true
    },
    {
        path: '/home',
        component: Home,
        name: '工艺管理',
        hidden: true,
        children: [
            { path: '/manufdetail', component: ManufactureDetail, name: '制造工艺详情页', hidden: true },
            { path: '/dividecompany', component: ManufactureCompany, name: '公司分类', hidden: true }
        ]
    },
    {
        path: '/home',
        component: Home,
        name: '公司',
        hidden: true,
        children: [
            { path: '/companydetail', component: CompanyDetail, name: '公司详情', hidden: true }
        ]
    },
    ...generateRoutesFromMenu(store.state.items)
];

export default routes;

// Menu should have 2 levels.  
function generateRoutesFromMenu (menu = [], routes = []) {  
	for (let i = 0, l = menu.length; i < l; i++) {  
	    let item = menu[i] 
	    if (item.path) {
	        routes.push(item)  
	    }
	}
	return routes  
}  